package org.apache.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Table;

import org.apache.util.Bet365;

@NamedNativeQueries({
        @NamedNativeQuery(
                name = "findByEventIdAndContractType",
                query = "select * from Contract c where c.contract_type = :contractType and c.event_id = :eventId",
                resultClass = Contract.class
        )
})
@Entity
@Table(name = "contract")
public class Contract extends ValueObject implements Serializable, Bet365 {

    private static final long serialVersionUID = 1L;

    public static final String CONTRACT_TYPE = "contractType";

    public static final String EVENT_ID = "event";

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumn(name = "event_id")
    private Event event;

    @Column(name = "contract_type")
    private String contractType;

    @Column(name = "bet_slip_url")
    private String betSlipUrl;

    private Float rate;
    private Boolean qualify;

    public String getBetSlipUrl() {

        return BET_SLIP_BASE + betSlipUrl;
    }

    public void setBetSlipUrl(String betSlipUrl) {

        this.betSlipUrl = betSlipUrl;
    }

    public Boolean getQualify() {

        return qualify;
    }

    public void setQualify(Boolean qualify) {

        this.qualify = qualify;
    }

    public String getContractType() {

        return contractType;
    }

    public void setContractType(String contractType) {

        this.contractType = contractType;
    }

    public Event getEvent() {

        return event;
    }

    public void setEvent(Event event) {

        this.event = event;
    }

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public Float getRate() {

        return rate;
    }

    public void setRate(Float rate) {

        this.rate = rate;
    }

    @Override
    public int hashCode() {

        return id.intValue();
    }

    @Override
    public boolean equals(Object obj) {

        if (obj instanceof Contract) {
            Contract c = (Contract) obj;
            if (c.getContractType().equals(contractType)) {
                return true;
            }
        }
        return false;
    }

}
